package daoimpl;

import dao.CommonDaoInter;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import java.io.Serializable;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.List;

/**
 * Created by Administrator on 2017/4/24.
 */
public class CommonDaoImpl<T> extends HibernateDaoSupport implements CommonDaoInter<T>{

    public Class getEntityClass(){
        Type type = this.getClass().getGenericSuperclass();
        ParameterizedType pt = (ParameterizedType)type;
        return (Class) pt.getActualTypeArguments()[0];
    }


    @Override
    public T get(Class<T> clazz, Serializable id) {
        return null;
    }

    @Override
    public void save(T entity) {
       this.getHibernateTemplate().save(entity);
    }

    @Override
    public List<T> queryAll() {
        return (List<T>) this.getHibernateTemplate().find("from " +this.getEntityClass().getName());
    }

    @Override
    public List<T> findList(Class<T> clazz, String where) {
        return null;
    }
}
